package controllers

import (
	"context"
	beego "github.com/beego/beego/v2/server/web"
	"gorm.io/gorm"
	"log"
	"shang/models"
	"strconv"
)

type AppendBlacklistController struct {
	beego.Controller
}

func (b *AppendBlacklistController) AppendBlacklist() {
	anchorid, _ := b.GetInt("anchor")
	userid, _ := b.GetInt("userid")
	user, _ := models.GetUserInfo(models.UserTwoWeek{
		Model: gorm.Model{ID: uint(userid)},
	})
	if user.ID == 0 {
		b.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "用户不存在",
		}
		b.ServeJSON()
		return
	}
	anchor := strconv.Itoa(anchorid)
	id := strconv.Itoa(userid)
	models.Redis.Set(context.Background(), anchor+"blacklist:"+id, "黑名单", 0)
	log.Println("11111111")
	b.Data["json"] = map[string]interface{}{
		"code": 200,
		"msg":  "加入黑名单成功",
	}
	b.ServeJSON()
}
